﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Odyssey.Linq;
using SunTzu.Web;
using SunTzu.Core.Data;

namespace Odyssey.Web.Areas.Admin.Controllers
{
    public class FormExhibitorController : BaseController<form_exhibitor>
    {
        public ActionResult Approve(int id)
        {
            var visitor = table.FirstOrDefault(c => c.Id == id);
            if (visitor != null)
            {
                HTMLHelper.BindModel(visitor);
                visitor.State = 1; // 确认审核
                visitor.UpdateDate = DateTime.Now;
                if (visitor.SaveOrUpdate())
                {
                    return Redirect("/Admin/FormExhibitor/List");
                }
            }
            SetMessage("审核失败！");
            return View("Edit", visitor ?? new form_exhibitor());
        }

        public override ActionResult List(int? page)
        {
            ViewData.Model = table
                // .Where(c => c.State > -1) // 过滤被逻辑删除的数据
                .OrderBy(c => c.State).ThenByDescending(c => c.Id)
                .ToPagedList(page.GetValueOrDefault(), numPerPage);
            return View();
        }
    }
}

